package com.hph.user;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * 服务器消费者引导类
 * @author {USER}
 * @date {date}
 */
@SpringBootApplication
@EnableDiscoveryClient
public class UserServiceConsumerBootstrap {

    public static void main(String[] args) {
        SpringApplication.run(UserServiceConsumerBootstrap.class, args);
    }

    /**
     * LoadBalanced:使用RestTemplateCustomizer对所有标注了@LoadBalanced的RestTemplate Bean
     * 添加了一个LoadBalancerInterceptor拦截器，而这个拦截器的作用就是对请求的URI进行转换获取到
     * 具体应该请求哪个服务实例ServiceInstance。
     * @return RestTemplate
     */
    @LoadBalanced
    @Bean
    public RestTemplate restTemplate(){

        return  new RestTemplate();
    }
}
